window.onload = function() {
    let btn = document.querySelector("button")
    let btn_post = document.querySelector("#btn_post")
    btn.addEventListener("click",(e)=>{
        let username = document.getElementById("username").value
        let password = document.getElementById("password").value
        fetch("http://172.19.1.251:8080/login",{
            method:"GET",
            headers:{
                "Content-Type":"application/x-www-form-url-encoded"
            }
        }).then(()=>{
            console.log("成功")
        }).catch(()=>{
            console.log("失败")
        })
    })
    
    btn_post.addEventListener("click",(e)=>{
        let username = document.getElementById("username").value
        let password = document.getElementById("password").value
        let data = {
            username:username,
            password:password
        }
        let dataJson = JSON.stringify(data)
        fetch("http://172.19.1.251:8080/login",{
            method:"POST",
            headers:{
                "Content-Type":"application/json"
            },
            body:dataJson
        }).then(()=>{
            console.log("成功")
        }).catch(()=>{
            console.log("失败")
        })
    })
}